<template>
  <div class="article-page">
    <nav class="my-nav van-hairline--bottom">
      <a
      @click="changeSorter('weight_desc')"
  :class="{ active: sorter === 'weight_desc' }"
  href="javascript:;"

      >推荐</a>
      <a href="javascript:;" :class="{ active: sorter === null }" @click="changeSorter(null)">最新</a>
      <div class="logo"><img src="@/assets/logo.png" alt=""></div>
    </nav>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
    <ArticleItem v-for="(item) in list" :key="item.id" :item="item"></ArticleItem>

    </van-list>
    <!-- <van-cell class="article-item" >
      <template #title>
        <div class="head">
          <img src="http://teachoss.itheima.net/heimaQuestionMiniapp/%E5%AE%98%E6%96%B9%E9%BB%98%E8%AE%A4%E5%A4%B4%E5%83%8F%402x.png" alt="" />
          <div class="con">
            <p class="title van-ellipsis">宇宙头条校招前端面经</p>
            <p class="other">不风流怎样倜傥 | 2022-01-20 00-00-00</p>
          </div>
        </div>
      </template>
<template #label>
        <div class="body van-multi-ellipsis--l2">
          笔者读大三, 前端小白一枚, 正在准备春招, 人生第一次面试, 投了头条前端, 总共经历了四轮技术面试和一轮hr面, 不多说, 直接上题&nbsp;一面
        </div>
        <div class="foot">点赞 46 | 浏览 332</div>
      </template>
</van-cell> -->
  </div>
</template>

<script>
import { getArticles } from '@/api/article'
// import { sort } from 'core-js/core/array'
export default {
  name: 'article-page',
  data () {
    return {
      list: [],
      current: 1,
      sorter: 'weight_desc',
      loading: false,
      finished: false
    }
  },
  methods: {
    // async cs () {
    //   const res = await getArticleList({
    //     current: this.current,
    //     sorter: this.sorter
    //   })
    //   console.log(res)
    // },
    async onLoad () {
      const res = await getArticles({
        current: this.current,
        // pageSize: 10,
        sorter: this.sorter
      })
      console.log(res)

      // console.log(data)
      // this.list = res.data.rows
      console.log(this.list)

      this.loading = false
      // 2.修改页码  this.current++
      this.current++
      // 3。追加数据 默认是第一页 ->
      this.list.push(...res.data.rows)

      if (this.current > res.data.pageTotal) {
        this.finished = true
      }
    },
    changeSorter (value) {
      this.sorter = value
      // 重置页码
      this.current = 1
      // 重置数据
      this.list = []
      // 结束状态（开启）
      this.finished = false
      // 开启loading效果
      this.loading = true
      // 重新请求列表
      this.onLoad()
    }
  }
}
</script>

<style lang="less" scoped>
.article-page {
  margin-bottom: 50px;
  margin-top: 44px;

  .my-nav {
    height: 44px;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    z-index: 999;
    background: #fff;
    display: flex;
    align-items: center;

    >a {
      color: #999;
      font-size: 14px;
      line-height: 44px;
      margin-left: 20px;
      position: relative;
      transition: all 0.3s;

      &::after {
        content: '';
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: 0;
        width: 0;
        height: 2px;
        background: #222;
        transition: all 0.3s;
      }

      &.active {
        color: #222;

        &::after {
          width: 14px;
        }
      }
    }

    .logo {
      flex: 1;
      display: flex;
      justify-content: flex-end;

      >img {
        width: 64px;
        height: 28px;
        display: block;
        margin-right: 10px;
      }
    }
  }
}

// .article-item {
//   .head {
//     display: flex;
//     img {
//       width: 40px;
//       height: 40px;
//       border-radius: 50%;
//       overflow: hidden;
//     }
//     .con {
//       flex: 1;
//       overflow: hidden;
//       padding-left: 10px;
//       p {
//         margin: 0;
//         line-height: 1.5;
//         &.title {
//           width: 280px;
//         }
//         &.other {
//           font-size: 10px;
//           color: #999;
//         }
//       }
//     }
//   }
//   .body {
//     font-size: 14px;
//     color: #666;
//     line-height: 1.6;
//     margin-top: 10px;
//   }
//   .foot {
//     font-size: 12px;
//     color: #999;
//     margin-top: 10px;
//   }
// }</style>
